package com.chuangxin.data.chazidian;

import com.chuangxin.data.core.IDBasedFetcher;
import com.chuangxin.data.core.io.DataOutput;
import com.chuangxin.data.core.io.FileWriter;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.File;

/**
 * Created by Dawnwords on 2015/2/1.
 */
public class ShiFetcher extends IDBasedFetcher {
    private static final int START_ID = 321;
    private static final int END_ID = 59833;
    private static final String URL_TEMPLATE = "http://shici.chazidian.com/shi${id}/";

    public ShiFetcher(DataOutput out) {
        super(out, START_ID, END_ID, URL_TEMPLATE);
    }

    @Override
    protected TitleContent processDoc(Document doc, String url) {
        String title = doc.select("div.content_title > h1").eq(0).html();
        Elements wrapper = doc.select("div.discription");
        wrapper.select("div").remove();
        wrapper.select("script").remove();
        wrapper.select("p#pages_next").remove();
        String content = wrapper.html();
        return new TitleContent(title, content);
    }

    public static void main(String[] args) {
        new ShiFetcher(new FileWriter("E:" + File.separator + "chazidian" + File.separator + "shi")).execute();
    }
}
